/*
 * @Author: zusw
 * @Date: 2020-01-16 14:06:09
 * @Description: 面包屑-从页面来的放在global命名空间中，有则使用它，没有用默认
 * @LastEditors  : zusw
 * @LastEditTime : 2020-01-20 17:51:37
 */
import React, { Component } from 'react'
import { Breadcrumb } from 'antd'
import { Link } from 'umi'
import { connect } from 'dva';
import styles from './index.less'

@connect(state => ({
  breads: state.global.breads,
}))
export default class Breads extends Component {
  render() {
    const { menuData, breads } = this.props;
    const newBreads = breads && breads.length > 0 ? [{usePath: '/', path: '/', breadcrumbName: '首页'}].concat(breads) : menuData;
    return (
      <Breadcrumb className={styles.my_bread}>
        {newBreads && newBreads.map((item,index) => {
          if(index === 0){
            return (
                <Breadcrumb.Item key={item.path}>
                  <Link to={item.path}>{item.breadcrumbName}</Link>
                </Breadcrumb.Item>
            )
          } else {
            return (
                <Breadcrumb.Item key={item.path}>
                  {item.breadcrumbName}
                </Breadcrumb.Item>
            )
          }
        })}
      </Breadcrumb>
    )
  }
}